/**
 * create by young (young2f@outlook.com) on 2020/10/1
 */
'use strict';
import React, {Component} from 'react';
import {Tag, Tooltip} from 'antd';
import styles from '../../index.less';

const _theme = require('../../theme');
export default class ElementItem extends Component {
  constructor(props) {
    super(props);

  }

  componentWillUnmount() {

  }

  getLevelColor(level) {
    switch (level) {
      case 0:
        return _theme['primary-color'];
      case 1:
        return _theme['primary-color-1'];
      case 2:
        return _theme['primary-color-2'];
      default:
        return _theme['primary-color'];
    }
  }

  /**
   *  <ul>
   <li>
   名称：{name}
   </li>
   <li>
   编码：{code}
   </li>
   </ul>
   * @returns {*}
   */
  render() {
    let {data, level, color = this.getLevelColor(level)} = this.props;
    const list = [];
    _.map(data, (item, index) => {
      const {key, value} = item;
      list.push(<tr>
        <th><Tag className={styles.tag} color={color}>{key}</Tag></th>
        <Tooltip title={value}>
          <td className={styles.text}>{value}</td>
        </Tooltip>
      </tr>);
    });
    return (
      <tbody>
      {list}
      </tbody>
    );
  }
}
